import { createAsyncThunk } from "@reduxjs/toolkit";
import RequestHandler from "http/RequestHandler";
import {PagingData, PagingResult} from "type/Page";
import {SecurityUser} from "type/entity/SecurityUser";

/** 请求用户的分页数据 */
export const fetchUserPageData = createAsyncThunk(
    'user/fetchUserPageData',
    async (paging: PagingData) => {
        return await RequestHandler.get<PagingResult<SecurityUser>>("/manager/admin/user/page/" + paging.page + "/" + paging.pageSize);
    }
);
/** 请求服务器添加用户数据 */
export const fetchAddUser = createAsyncThunk(
    'user/fetchAddUser',
    async (user: SecurityUser) => {
       return await RequestHandler.put<number>("/manager/admin/user", user);
    }
);
/** 请求服务器修改用户数据 */
export const fetchUpdateUser = createAsyncThunk(
    'user/fetchUpdateUser',
    async (user: SecurityUser) => {
        return await RequestHandler.post<number>("/manager/admin/user", user);
    }
);
/** 请求服务器删除用户数据 */
export const fetchDeleteUser = createAsyncThunk(
    'user/fetchDeleteUser',
    async (userId: number) => {
        return await RequestHandler.delete<number>("/manager/security-user/" + userId);
    }
);
